﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Eventbrite.LinqProvider
{
   public  class EventbriteQuery<T>:IOrderedQueryable<T>, IQueryable<T> 
    {
       QueryProvider _provider;
       Expression _expression;

       public EventbriteQuery(QueryProvider provider) {

           
           _provider = provider;
           _expression = Expression.Constant(this);
       
       }

       public EventbriteQuery(QueryProvider provider, Expression expression)
       {
           _provider = provider;
           _expression = expression;
       }

       public IEnumerator<T> GetEnumerator()
        {
            return (this._provider.Execute(this._expression) as IEnumerable<T>).GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((System.Collections.IEnumerable)this._provider.Execute(this._expression)).GetEnumerator();
        }

      
        public Type ElementType
        {
            get { return typeof(T); }
        }

        public System.Linq.Expressions.Expression Expression
        {
            get { return _expression; }
        }

        public IQueryProvider Provider
        {
            get { return _provider; }
        }
    }
}
